Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upgrade): two-way binding and listening for event #22772

Conversation

FDIM
Copy link
Contributor

@FDIM FDIM commented Mar 14, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

It is not possible to have a two-way binding and listening to an event in downgraded component. Bound value would remain outdated and only event listener expression would be evaluated.

Issue Number: #22734

What is the new behavior?

Bound value will be updated first when new value is emitted and then expression (if any) will be evaluated.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@FDIM FDIM force-pushed the bugfix/two-way-binding-and-expressions-on-same-output branch 2 times, most recently from a681727 to 97bedce Compare March 14, 2018 20:12
@gkalpak gkalpak added type: bug/fix comp: upgrade/dynamic target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 14, 2018
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change LGTM 👍

The added test only tests the (now deprecated) dynamic version of ngUpgrade. We mainly need tests for the static version (with both UpgradeModule and downgradeComponent()); e.g. in downgrade_component_spec.ts and downgrade_module_spec.ts.
(Also, that particular test you modified is already very hard to follow. It would be nice if you could add new tests specifically focused on the fix 🙏)

emitter.subscribe({
next: assignExpr ? (v: any) => setter !(this.scope, v) :
private subscribeToOutput(
output: PropertyBinding, expr: string|null, isAssignment: boolean = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expr shouldn't be null at this point. Can you change the type (and also remove the check below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check if that doesn't cause any issues as the if before calling this only tests if the property is there, not that it's not null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be very weird for attrs.someProp to be set to null (as one would have a directive to specifically do that, which doesn't make much sense) and this would only matter is isAssignment is true. But you have a point; there is no good reason to unnecessarily break a weird usecase 😁

Let's leave it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, and very unlikely - I hope you don't mind that I've removed the check.

@FDIM
Copy link
Contributor Author

FDIM commented Mar 15, 2018

Yeah, that test is quite something. Sad part is that it was the only one that failed if setupOutputs method did nothing, hence why I've changed it. I'll try to update the specs you mentioned and cover the code I've changed later today.

@FDIM FDIM force-pushed the bugfix/two-way-binding-and-expressions-on-same-output branch from 97bedce to 1eab1f3 Compare March 15, 2018 19:30
@FDIM
Copy link
Contributor Author

FDIM commented Mar 15, 2018

I've reverted the test in dynamic version, added a new spec in static/integration/downgrade_component_spec.ts and hoping that all is good now

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except it would be nice to have a similar test for the dynamic version as well.

@gkalpak gkalpak added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 15, 2018
@gkalpak
Copy link
Member

gkalpak commented Mar 15, 2018

Also, the commit message is a little confusing in that it makes the bug sound specific to model/model-change (which is not the case).

Changes would not propagate to a value in downgraded component in case you had two-way binding and listening to a value-change, e.g. [(value)]="value" (value-change)="fetch()"

Closes angular#22734
@FDIM FDIM force-pushed the bugfix/two-way-binding-and-expressions-on-same-output branch from 1eab1f3 to 5b41d62 Compare March 16, 2018 20:18
@FDIM
Copy link
Contributor Author

FDIM commented Mar 16, 2018

I've updated the message a bit and also copied and adapted the test to ensure that dynamic version is also working

@gkalpak
Copy link
Member

gkalpak commented Mar 19, 2018

LGTM, thx 👍
(Waiting for Travis to go green (seems to have flaked) and will mark for merge.)

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Mar 19, 2018
@mhevery
Copy link
Contributor

mhevery commented Mar 19, 2018

mhevery pushed a commit that referenced this pull request Mar 20, 2018
Changes would not propagate to a value in downgraded component in case you had two-way binding and listening to a value-change, e.g. [(value)]="value" (value-change)="fetch()"

Closes #22734

PR Close #22772
@mhevery mhevery closed this in 2b3de63 Mar 20, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
Changes would not propagate to a value in downgraded component in case you had two-way binding and listening to a value-change, e.g. [(value)]="value" (value-change)="fetch()"

Closes angular#22734

PR Close angular#22772
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants